package com.controller;/**
 * @AUTHOR: 我是章璐锋憨憨
 * @Data:
 * @Version:
 */

import com.pojo.Provider;
import com.utils.DSUtil;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @outhor RD
 * 2021/12/23
 */
@WebServlet("/demo")
public class DemoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        Integer pageNow = Integer.valueOf(req.getParameter("page"));
        Integer pageSize = Integer.valueOf(req.getParameter("limit"));
        List<Provider> listPage = DSUtil.query("select * from provider limit ?,?", Provider.class, (pageNow-1) * pageSize, pageSize);

        List<Provider> list = DSUtil.query("select * from provider", Provider.class);
        JSONObject jo = new JSONObject();
        jo.put("code", 0);
        jo.put("msg", "");
        jo.put("count", list.size());
        jo.put("data", listPage);
//        writer.print(jo);
        resp.getWriter().print(jo);
    }
}
